package com.ignitetest.datanode

import org.apache.ignite.Ignition
import org.apache.ignite.cache.QueryEntity
import org.apache.ignite.configuration.CacheConfiguration
import org.apache.ignite.configuration.IgniteConfiguration
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi
import org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder
import java.util.*

/**
 * Created by User on 2017/5/22.
 */
object DataNodeServer3 {
    @JvmStatic fun main(args: Array<String>) {
        val cacheCfg = CacheConfiguration<Any, Any>("personCache")
        val entity = QueryEntity("CustomKey", "Person")
        val flds = LinkedHashMap<String, String>()
        flds.put("id", String::class.java.name)
        flds.put("firstName", String::class.java.name)
        flds.put("lastName", String::class.java.name)
        entity.fields = flds
        // Listing a subset of the fields that belong to the key.
        val keyFlds = HashSet<String>()
        keyFlds.add("id");
        entity.setKeyFields(keyFlds);
// End of new settings, nothing else here is DML related
        entity.setIndexes(Collections.emptyList());
        cacheCfg.setQueryEntities(Collections.singletonList(entity));

        // Create new configuration.
        val cfg = IgniteConfiguration();
        cfg.setCacheConfiguration(cacheCfg);


        val ipFinder = TcpDiscoveryMulticastIpFinder();
        ipFinder.setAddresses(Arrays.asList("127.0.0.1:47500..47509"));
        val tcpDiscoverySpi = TcpDiscoverySpi();
        tcpDiscoverySpi.setIpFinder(ipFinder);
        cfg.setDiscoverySpi(tcpDiscoverySpi);
        // Start Ignite node with given configuration.
        Ignition.start(cfg);
    }
}